<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/29
 * Time: 22:03
 */
header('content-type:text/html;charset=utf-8');
require './public_function.php';
//dbInit();
$link = mysqli_connect('localhost','root','','itcast');
if(!$link) {
    die('链接数据库失败' . mysqli_error($link));
}
mysqli_query($link,'set names utf8');
$e_id = isset($_GET['e_id']) ? intval($_GET['e_id']) : 0;
if(!empty($_POST)){
    $update = array();
    $fields = array('e_name','e_dept','date_of_birth','date_of_entry');
    foreach ($fields as $v){
        $data = isset($_POST[$v]) ? $_POST[$v] : '';
        if($data == '') die;
        $data =safeHandle($link,$data);
        $update[] = "`$v`='$data'";
    }
    $update_str = implode(',',$update);
    $sql = "update `emp_info` set $update_str where `e_id`=$e_id";
    if($res = mysqli_query($link,$sql)) {
        header("Location: ./showList.php");
    }else{
        die('员工信息修改失败！');
    }
}else{
    $sql = "select * from `emp_info` WHERE `e_id`=$e_id";
    $emp_info = fetchRow($link,$sql);
    define('APP','itcast');
    require './updata_html.php';
}